<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/1
 * Time: 下午6:46
 */
class Base extends MY_Admin_Controller
{
    public function index()
    {
    	$page = intval($this->input->get_post('page'));
    	$page = $page ? $page : 1;
    	
    	$uid = intval($this->input->get_post('uid'));
    	$cid = intval($this->input->get_post('cid'));
    	$start_time = trim($this->input->get_post('start_time'));
    	$end_time = trim($this->input->get_post('end_time'));
    	$uname = trim($this->input->get_post('uname'));
    	
    	$where = array();
    	if($uid){
    		$where['fbl.uid'] = $uid;
    	}
    	
    	if($cid){
    		$where['fbl.cid'] = $cid;
    	}
    	
    	if($start_time){
    		$where['fbl.create_time>'] = $start_time;
    	}
    	
    	if($end_time){
    		$where['fbl.create_time<'] = $end_time;
    	}
    	
    	if($uname){
    		$where['fbl.uname'] = $uname;
    	}
    	
    	$this->load->model('finance/model_finance_base_log','finance_base_log');
    	$total_rows = $this->finance_base_log->more_count($where);
    	
    	
    	//分页
    	$this->load->library('pagination');
    	
    	$config['total_rows'] = $total_rows;
    	$config['per_page'] = 20;
    	$config['base_url'] = '/finance/Base/index';
    	
    	$this->pagination->initialize($config);
    	$show_page = $this->pagination->create_links();
    	
    	
    	//读取数据
    	$offset = ($page-1) * $config['per_page'];
        $financeInfo = $this->finance_base_log->more_lists($offset,  $config['per_page'], $where);
        
        $cid_arr = array(
        		'22'=>'竞拍收',
        		'24'=>'打赏收',
        		'23'=>'围观收',
        		'1'=>'充值',
        		'12'=>'互赠转入',
        		'5'=>'解冻',
        		'26'=>'个人推广收入',
        		'25'=>'广告收入',
        		
        		'20'=>'竞拍支',
        		'13'=>'打赏支',
        		'14'=>'围观支',
        		'10'=>'提现',
        		'11'=>'互赠转出',
        		'6'=>'冻结',
        		'21'=>'广告支出',
        );

        $data = array(
            'financeInfo' => $financeInfo,
        	'show_page'   => $show_page,
        	'total_rows'  => $config['total_rows'],
        	'cid_arr'     => $cid_arr,
        );
        
        $this->load->view('admin/finance/base/index', $data);
    }
    
    public function summary()
    {
        //充值金额
    	$this->load->model('finance/Model_finance_payment', 'fp');
    	$data['recharge'] = ($this->fp->sum() * 10);


    	//用户余额
    	$this->load->model('finance/Model_finance_user_capital_account', 'fuca');
    	$data['balance'] = $this->fuca->sum();


        //提现金额
    	$this->load->model('finance/Model_finance_withdrawals', 'fw');
    	$data['withdrawals'] = $this->fw->sum();


        //未解冻
    	$this->load->model('finance/Model_finance_base_log', 'fbl');
    	$data['freeze'] = $this->fbl->sum();


    	//差异
    	bcscale(3);
    	$data['difference'] = bcsub($data['recharge'], bcadd(bcadd($data['balance'], $data['withdrawals']), $data['freeze']));
        //sp($data['recharge'], $data['balance'], $data['withdrawals'], $data['freeze'], $data['difference']);

    	//弹幕
    	$data['cid_19'] = $this->fbl->sum('cid=19');
    	$data['cid_26'] = $this->fbl->sum('cid=26');


    	//直播间广告投放
    	$data['cid_21'] = $this->fbl->sum('cid=21');
    	$data['cid_25'] = $this->fbl->sum('cid=25');


    	//消费道具
    	$data['cid_13'] = $this->fbl->sum('cid=13');
    	$data['cid_24'] = $this->fbl->sum('cid=24');


    	//观看直播消费
    	$data['cid_14'] = $this->fbl->sum('cid=14');
    	$data['cid_23'] = $this->fbl->sum('cid=23');


    	//竞拍
    	$data['cid_20'] = $this->fbl->sum('cid=20');
    	$data['cid_22'] = $this->fbl->sum('cid=22');


    	//转赠
    	$data['cid_11'] = $this->fbl->sum('cid=11');
    	$data['cid_12'] = $this->fbl->sum('cid=12');


    	//连麦
        $data['cid_33'] = $this->fbl->sum('cid=33');
        $data['cid_34'] = $this->fbl->sum('cid=34');


    	$this->load->view('admin/finance/base/summary', $data);
    }
}